'----------------------------------------------
' Name: Ali Karbassi & Ben Sattler
' Date: February 15, 2007
' Description: Program 2
'              Class House
'----------------------------------------------
Public Class House
   Implements IDisposable

   Private _ID As String
   Private _ID_written As Boolean
   Private _Rooms As Integer
   Private _Garages As Integer
   Protected _PriceSet As Boolean
   Protected _Price As Double
   Protected Shared theCount As Integer

   ''' <summary>
   ''' Returns House Type
   ''' </summary>
   ''' <value></value>
   ''' <returns></returns>
   ''' <remarks></remarks>
   Public Overridable ReadOnly Property Type() As String
      Get
         Return "House"
      End Get
   End Property

   ''' <summary>
   ''' Returns and/or sets the id. Checks for 5 characters/letters/digits. Returns errors if errors are found.
   ''' </summary>
   ''' <value></value>
   ''' <returns></returns>
   ''' <remarks></remarks>
   Public Property ID() As String
      Get
         Return _ID
      End Get
      Set(ByVal value As String)

         If Not _ID_written Then

            If value.Length <> 5 Then
               Err.Raise(33409, "Property ID", "ID must be 5 characters!")
            Else

               Dim x As Integer

               For x = 0 To value.Length - 1
                  If Not Char.IsLetterOrDigit(value(x)) Then
                     Err.Raise(33409, "Property ID", "Each character of the ID must be a digit or letter.")
                  End If
               Next x

               _ID = value
               _ID_written = True

            End If

         Else
            Err.Raise(33409, "ID", "Value has been writen already.")
         End If

      End Set
   End Property

   ''' <summary>
   ''' Gets and/or sets Rooms
   ''' </summary>
   ''' <value></value>
   ''' <returns></returns>
   ''' <remarks></remarks>
   Public Property Rooms() As Integer
      Get
         Return _Rooms
      End Get
      Set(ByVal value As Integer)
         _Rooms = value
      End Set
   End Property

   ''' <summary>
   ''' Gets and/or sets Garages
   ''' </summary>
   ''' <value></value>
   ''' <returns></returns>
   ''' <remarks></remarks>
   Public Property Garages() As Integer
      Get
         Return _Garages
      End Get
      Set(ByVal value As Integer)
         _Garages = value
      End Set
   End Property

   ''' <summary>
   ''' Returns the price.
   ''' </summary>
   ''' <value></value>
   ''' <returns></returns>
   ''' <remarks></remarks>
   Public ReadOnly Property Price() As Double
      Get
         Return _Price
      End Get
   End Property

   ''' <summary>
   ''' Returns the total count.
   ''' </summary>
   ''' <value></value>
   ''' <returns></returns>
   ''' <remarks></remarks>
   Public Shared ReadOnly Property TotalCount() As String
      Get
         Return theCount.ToString
      End Get
   End Property

   ''' <summary>
   ''' Event for ID changed.
   ''' </summary>
   ''' <param name="ID"></param>
   ''' <remarks></remarks>
   Public Event Changed(ByVal ID As String)

   ''' <summary>
   ''' Calls Changed()
   ''' </summary>
   ''' <param name="ID"></param>
   ''' <remarks></remarks>
   Protected Sub HasChanged(ByVal ID As String)
      RaiseEvent Changed(ID)
   End Sub

   ''' <summary>
   ''' Handles the ID if it was changed.
   ''' </summary>
   ''' <param name="ID"></param>
   ''' <remarks></remarks>
   Private Sub HandlesChanged(ByVal ID As String) Handles Me.Changed
      MsgBox("The price for house " & ID & " has changed!", MsgBoxStyle.OkOnly)
   End Sub

   ''' <summary>
   ''' Sets the price
   ''' </summary>
   ''' <remarks></remarks>
   Public Overridable Sub setPrice()
      _Price = 0
      HasChanged(_ID)
   End Sub

   ''' <summary>
   ''' Sets the rooms.
   ''' </summary>
   ''' <remarks></remarks>
   Public Overridable Sub setRooms()

   End Sub

   ''' <summary>
   ''' Sets the garages.
   ''' </summary>
   ''' <remarks></remarks>
   Public Overridable Sub setGarages()

   End Sub

   Private disposedValue As Boolean = False      ' To detect redundant calls

   ' IDisposable
   Protected Overridable Sub Dispose(ByVal disposing As Boolean)
      If Not Me.disposedValue Then
         If disposing Then
            ' TODO: free unmanaged resources when explicitly called
         End If
         theCount -= 1
         ' TODO: free shared unmanaged resources
      End If
      Me.disposedValue = True
   End Sub

#Region " IDisposable Support "
   ' This code added by Visual Basic to correctly implement the disposable pattern.
   Public Sub Dispose() Implements IDisposable.Dispose
      ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
      Dispose(True)
      GC.SuppressFinalize(Me)
   End Sub
#End Region

End Class
